package com.zfzs.post.modules.agent.repository;

import com.zfzs.post.modules.agent.domain.AgentMoney;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.math.BigDecimal;

/**
* @author ck
* @date 2019-08-07
*/
public interface AgentMoneyRepository extends JpaRepository<AgentMoney, Long>, JpaSpecificationExecutor {

    //提现操作
    @Modifying
    @Query(value = "update agent_money set version = version + 1,usable_money = usable_money - ?2,frozen_money = frozen_money + ?2,update_time = now() where id = ?1 and version = ?3",nativeQuery = true)
    int withdrawMoney(Long id, BigDecimal money,Long version);

}